<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:pe="http://primefaces.org/ui/extensions">
    <h:head>
        <title>#{bundle.loanclosure}</title>
        <link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
    </h:head>
    <h:body>
        <ui:composition>
            <h:form prependId="false">
               <script type="text/javascript">  
                   var doInitForm=false;
                   var tofocus;
                   
                   function changeFocus(nextfcs) {tofocus=nextfcs;}
                   function setDoInitForm(st) {doInitForm=st;}
                   function focusState(xhr, status, args) {  
                       if(args.validationFailed || !args.success) {}
                       else document.getElementById(tofocus).focus();
                       return false;
                   }
                                      
                   function handleCompleteSaving(xhr, status, args) {  
                        if(args.validationFailed || !args.success) {
                        }else setTimeout(function() {if (doInitForm==true) btnNewLoanclose.jq.click();}, 3000);
                    }
                    
                    function customRK(e, id, nextfcs) {
                      var code = (e.keyCode ? e.keyCode : e.which);
                       if(code==13) {
                            if (id=="loanclosureLoanNo") {
                               rcloanclosureGetLoan();
                               tofocus=nextfcs;
                            }
                            e.preventDefault ? e.preventDefault() : e.returnValue = false;
                            e.stopPropagation();
                       }
                    }
                    
                    
                    
                </script>  
                
                <p:outputPanel autoUpdate="true">
                <p:toolbar >
                    <p:toolbarGroup align="left">
                        <p:commandButton value="#{bundle.btnNew}" icon="ui-icon-document" widgetVar="btnNewLoanclose"
                                         action="#{loanclosureBean.newData()}" process="@this" oncomplete="setDoInitForm(false);"
                                         update="displayLoanclosure" >
                            <pe:resetEditableValues for="displayLoan"/>  
                        </p:commandButton> 
                        
                        <p:commandButton value="#{bundle.btnSave}" icon="ui-icon-disk"
                                         action="#{loanclosureBean.save()}"  
                                         oncomplete="setDoInitForm(true); handleCompleteSaving(xhr, status, args);"
                                         update="displayLoanclosure" disabled="#{!loanclosureBean.editMode}" >
                        </p:commandButton> 
                    </p:toolbarGroup>
                </p:toolbar>
                </p:outputPanel>
                
                <p:remoteCommand name="rcloanclosureGetLoan" actionListener="#{loanclosureBean.getLoan('null')}" process="loanclosureLoanNo @this" 
                                 update="displayLoanclosure loancloseCustInfo" oncomplete="focusState(xhr, status, args);"/>
                
                <!-- LOOK UP saving -->
                <p:dialog header="#{bundle.Select} #{bundle.loanNo}" widgetVar="dlgLoanCloseLookupLoan" closable="true" dynamic="true" >
                    <p:ajax listener="#{loanclosureBean.handleCloseLookup}" />
                    <h:panelGrid id="displayLoancloseLookup" rendered="#{loanclosureBean.showLookup==true}">
                        <ui:include src="../loan/searchLoan.xhtml" >
                            <ui:param name="lookupLoanComponenId" value="loanclose" />
                            <ui:param name="loanApprovalUid" value="#{1}" />
                        </ui:include> 

                        <h:panelGrid cellpadding="0" styleClass="pComBtnSTDR" >
                            <f:facet name="footer">
                                <p:commandButton value="#{bundle.btnOK}" icon="ui-icon-disk" immediate="true" 
                                                process="@this" update="displayLoanclosure"
                                                action="#{loanclosureBean.getLoan(searchLoanBean.selectedData.loanNo)}" 
                                                oncomplete="dlgLoanCloseLookupLoan.hide(); focusState(xhr, status, args);" />

                                <p:commandButton value="#{bundle.btnClose}" oncomplete="dlgLoanCloseLookupLoan.hide()" immediate="true" icon="ui-icon-document" process="@this" />
                            </f:facet>
                        </h:panelGrid>
                    </h:panelGrid>    
                </p:dialog>
                
                <h:panelGrid id="displayLoanclosure" styleClass="addELIT" cellpadding="0" >
                    <h:panelGrid columns="2" cellpadding="1" columnClasses="panelGridId" >
                        <p:panel header="#{bundle.loanLedgend}">
                            <h:panelGrid columns="2" cellpadding="1">
                                <h:outputLabel style="padding:0 15px 0 0;" value= "#{bundle.closingDate} :" />
                                <h:outputText value="#{loanclosureBean.loanclosure.closureDate}" />

                                <h:outputLabel value= "#{bundle.loanNo} :" />
                                <h:panelGrid columns="2" cellpadding="0" cellspacing="0">
                                    <p:inputText value="#{loanclosureBean.loanclosure.loan.loanNo}" 
                                                onkeydown="customRK(event, 'loanclosureLoanNo', '#{utilityBean.findClientId('loanclosureReason')}')" 
                                                id="loanclosureLoanNo" label="#{bundle.loanNo}" disabled="#{!loanclosureBean.editMode}"
                                                required="true" requiredMessage="#{bundle.loanNo} #{bundle.requiredInput}" >
                                        <p:ajax update="msgloanclosureLoanNo" process="@this" />
                                    </p:inputText>
                                    
                                    <p:commandButton icon="ui-icon-search" iconPos="center" styleClass="btnSmall"
                                                     update="displayLoancloseLookup" onclick="changeFocus('#{utilityBean.findClientId('loanclosureReason')}');"
                                        process="@this" immediate="true" oncomplete="dlgLoanCloseLookupLoan.show();" disabled="#{!loanclosureBean.editMode}">
                                        <f:setPropertyActionListener target="#{loanclosureBean.showLookup}" value="#{true}" />
                                    </p:commandButton>
                                    
                                    <p:message id="msgloanclosureLoanNo" for="loanclosureLoanNo" display="icon" />
                                </h:panelGrid>

                                <h:outputLabel value= "#{bundle.loanAmount} :" />
                                <h:outputText value="#{loanclosureBean.loanclosure.loan.owningAmount}" >
                                    <f:convertNumber groupingUsed="true" />
                                </h:outputText>

                                <h:outputLabel value= "#{bundle.reason} :" />
                                <h:panelGrid columns="2" cellpadding="0" cellspacing="0">
                                    <p:inputTextarea value="#{loanclosureBean.loanclosure.reason}" 
                                                onkeydown="customRK(event, '')" rows="3" cols="50" autoResize="false"
                                                id="loanclosureReason" label="#{bundle.reason}" disabled="#{!loanclosureBean.editMode}"
                                                requiredMessage="#{bundle.reason} #{bundle.requiredInput}" >
                                        <p:ajax event="keyup" update="msgloanclosureReason" process="@this" />
                                    </p:inputTextarea>
                                    <p:message id="msgloanclosureReason" for="loanclosureReason" display="icon" />
                                </h:panelGrid>
                            </h:panelGrid>
                        </p:panel>

                        <p:outputPanel autoUpdate="true" id="loancloseCustInfo">
                        <p:panel header="#{bundle.cusledgen}">
                            <h:panelGrid columns="2" style="width: 100%" >
                                <h:outputLabel value= "#{bundle.cif} :" />
                                <h:outputText value="#{loanclosureBean.loanclosure.loan.customer.cif}" />

                                <h:outputLabel value= "#{bundle.globalName} :" />
                                <h:outputText value="#{loanclosureBean.loanclosure.loan.customer.customerName}" />

                                <h:outputLabel value= "#{bundle.aliasName} :" />
                                <h:outputText value="#{loanclosureBean.loanclosure.loan.customer.aliasName}" />

                                <h:outputLabel value= "#{bundle.npwp} :" />
                                <h:outputText value="#{loanclosureBean.loanclosure.loan.customer.npwp}" />

                                <h:outputLabel style="padding: 0 15px 0 0;" value= "#{bundle.officePhone} :" />
                                <h:outputText value="#{loanclosureBean.loanclosure.loan.customer.cusper.officePhone}"/>

                                <h:outputLabel value= "#{bundle.phone} :" />
                                <h:outputText value="#{loanclosureBean.loanclosure.loan.customer.phone}"/>

                                <h:outputLabel value= "#{bundle.mobilePhone} :" />
                                <h:outputText value="#{loanclosureBean.loanclosure.loan.customer.mobilePhone}"/>
                                
                                <h:outputLabel value= "#{bundle.specimen}" /><h:outputLabel value=":"/>
                                <p:graphicImage  value="/upload/personal/#{loanclosureBean.loanclosure.loan.customer.specimen}" />
                            </h:panelGrid>
                        </p:panel>
                        </p:outputPanel>
                    </h:panelGrid>
                </h:panelGrid>
            </h:form> 
        </ui:composition>        
    </h:body>
</html>

